#ifndef duinolab_h
#define duinolab_h

#include <WProgram.h>

#include "mcp23009.h"
#include <../../../../../libraries/Wire/Wire.h>
#include <inttypes.h>

#define  BUTTON_PERIPHERAL 0
#define  POT_PERIPHERAL    1
#define  LED_PERIPHERAL    2

#define  BUTTON_PERIPHERAL_ADDR  (0x4E >> 1)  // everything shifted right 1 bit - Wire adds last bit itself
#define  POT_PERIPHERAL_ADDR     (0x40 >> 1)  // everything shifted right 1 bit - Wire adds last bit itself
#define  LED_PERIPHERAL_ADDR     (0x4A >> 1)  // everything shifted right 1 bit - Wire adds last bit itself

#define  LED_YELLOW 0
#define  LED_AMBER  1
#define  LED_ORANGE 2
#define  LED_RED    3
#define  LED_GREEN  4
#define  LED_BLUE   5

#define  BUTTON_YELLOW 6
#define  BUTTON_ORANGE 7
#define  BUTTON_GREEN  8
#define  BUTTON_BLUE   9

#define  POT_BLACK 10
#define  POT_RED   11

#define  NUM_CONTROLS 12

class DuinolabClass
{
  public:
    void Init();
    void ConnectToArduino(uint8_t peripheral);
    void LEDOn(uint8_t led, uint8_t brightness = 255);
    void LEDOff(uint8_t led);
    uint16_t ReadPot(uint8_t pot);
    uint8_t ButtonPressed(uint8_t button);
  private:
    mcp23009  _peripheral[3];
    uint8_t _assign_peripheral[NUM_CONTROLS];
    uint8_t _assign_port[NUM_CONTROLS];
    uint8_t _assign_duinopin[NUM_CONTROLS];
};

extern DuinolabClass Duinolab;

#endif // #ifndef
